package com.qzsoft.zhjd.asphalt.modules.consumptionstatistics.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.qzsoft.zhjd.asphalt.modules.consumptionstatistics.dto.ActCountDto;
import com.qzsoft.zhjd.asphalt.modules.consumptionstatistics.dto.ConsumptionStatisticsTableDto;
import com.qzsoft.zhjd.asphalt.modules.consumptionstatistics.dto.TheoCountDto;
import com.qzsoft.zhjd.asphalt.modules.consumptionstatistics.mapper.ConsumptionStatisticsMapper;
import com.qzsoft.zhjd.asphalt.modules.consumptionstatistics.service.ConsumptionStatisticsService;
import com.qzsoft.zhjd.common.components.BaseServiceComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ConsumptionStatisticsServiceImpl implements ConsumptionStatisticsService {
    @Autowired
    private ConsumptionStatisticsMapper consumptionStatisticsMapper;

    @Autowired
    private BaseServiceComponent baseServiceComponent;

    /**
     * 数据分页
     *
     * @param params
     * @return
     */
    @Override
    public IPage<ConsumptionStatisticsTableDto> page(Map<String, Object> params) {
        String reportType = ObjectUtils.isEmpty(params.get("reportType")) ? "all" : params.get("reportType").toString();
        params.put("reportType", reportType);
        //分页条件
        IPage<ConsumptionStatisticsTableDto> page = baseServiceComponent.getPage(params, ConsumptionStatisticsTableDto.class);
        return consumptionStatisticsMapper.reportPage(page, params);
    }

    /**
     * 获取实际材料消耗
     *
     * @param params
     * @return
     */
    @Override
    public ActCountDto actCount(Map<String, Object> params) {
        String reportType = ObjectUtils.isEmpty(params.get("reportType")) ? "all" : params.get("reportType").toString();
        params.put("reportType", reportType);
        ActCountDto actCountDto = consumptionStatisticsMapper.actCount(params);
        return actCountDto;
    }

    /**
     * 理论材料消耗
     *
     * @param params
     * @return
     */
    @Override
    public TheoCountDto theoCount(Map<String, Object> params) {
        String reportType = ObjectUtils.isEmpty(params.get("reportType")) ? "all" : params.get("reportType").toString();
        params.put("reportType", reportType);
        return consumptionStatisticsMapper.theoCount(params);
    }
}
